/*=============================================================================
*
*   Copyright (C) 2020 All rights reserved.
*
*   Filename:		sorting.hpp
*
*   Author: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Date: 2020-03-04 23:39
*
*   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Last modified:	2020-03-27 10:33
*
*   Description:
*
=============================================================================*/
#ifndef SORTING_H
#define SORTING_H

#include "../util/indexed.hpp"
#include <boost/geometry.hpp>
#include <boost/geometry/strategies/cartesian/centroid_average.hpp>


namespace geoxfem {
namespace algorithm {

template <typename P>
struct clock_wise {};

template <typename P>
struct distance_ascending {
  P m_startP;
  distance_ascending(const P& _pt) : m_startP(_pt) {}
  bool operator()(const P& pt1, const P& pt2) const {
    return boost::geometry::comparable_distance(pt1, m_startP)
           < boost::geometry::comparable_distance(pt2, m_startP);
  }
  bool operator()(P* pt1, P* pt2) const {
    return boost::geometry::comparable_distance(*pt1, m_startP)
           < boost::geometry::comparable_distance(*pt2, m_startP);
  }
};

struct index_ascending {
  bool operator()(const util::Indexed* obj1, const util::Indexed* obj2) {
    return *obj1 > *obj2;
  }
  bool operator()(const util::Indexed& obj1, const util::Indexed& obj2) {
    return obj1 < obj2;
  }
};

}  // namespace algorithm
}  // namespace geoxfem

#endif /* SORTING_H */
